<?php
require_once 'Zend/Db/Table/Abstract.php';

class Theme extends Zend_Db_Table_Abstract {
	protected $_name = 'theme';
	protected $_primary = 'id';
	
	protected $_dependentTables = array(
		'ThemeResourceMap',
		'ThemeCategoryMap'
	);
	
	/**
	 * Find theme by id.
	 * 
	 * @param $id theme id
	 */
	public function findById($id) {
		return $this->find($id)->current();
	}
	
	/**
	 * Find all avaiable themes.
	 */
	public static function findAllAvaiableThemes() {
		$theme = new Theme();
		$select = $theme->select();
		$select->from($theme->_name, array('id', 'name', 'description'));
		return $theme->fetchAll($select);
	}
	
	/**
	 * Find resouce by given resource type.
	 * 
	 * @param $theme theme object
	 * @param $resource_type resoucre type
	 */
	public static function getResourceByType($theme, $resource_type) {
		$r=new Resource();
		$select=$r->select()->where('resource_type=?', $resource_type);
		return $theme->findManyToManyRowset('Resource', 'ThemeResourceMap', 'Theme', 'Resource', $select);
	}
}